package com.lineng.util;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;

public class VerificationUtil {
	public static int verification(HttpServletRequest request) {

		// 获取Cookie遍历拿到JSESSIONID
		if (request.getCookies() != null) {
			Cookie[] cookies = request.getCookies();
			if (cookies.length > 0) {
				String JSESSIONID = "";
				for (Cookie cookie : cookies) {
					switch (cookie.getName()) {
					case "JSESSIONID":
						JSESSIONID = cookie.getValue();
						break;
					default:
						break;
					}
				}

				if (request.getSession(false) != null) {
					if (request.getSession().getAttribute("username") != null) {
						if (JSESSIONID.equals(request.getSession().getId())) {
							return 1;
						}
					}
				}
			}
		}

		return 0;
	}

}
